package com.fanhao.dllo.soundfm.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.fanhao.dllo.soundfm.R;
import com.fanhao.dllo.soundfm.entity.InforSubTypeResult;
import com.fanhao.dllo.soundfm.fragment.BaseFragment;
import com.fanhao.dllo.soundfm.utils.CountToOthers;

import java.util.List;

/**
 * Created by dllo on 16/1/19.
 */
public class InforOneAdapter extends BaseAdapter {
    private Context context;
    private List<InforSubTypeResult.ListEntity> list;

    public InforOneAdapter(Context context) {
        this.context = context;
    }

    // 获得集合
    public void addInforSubTypeData(List<InforSubTypeResult.ListEntity> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list != null && list.size() > 0 ?
                list.size() : 0;
    }

    @Override
    public Object getItem(int position) {

        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (list != null && list.size() > 0) {
            InforTwoViewHolder inforHolder = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(context)
                        .inflate(R.layout.fragment_inforstypeone_adapter_item, parent, false);
                inforHolder = new InforTwoViewHolder(convertView);
                convertView.setTag(inforHolder);
            } else {
                inforHolder = (InforTwoViewHolder) convertView.getTag();
            }
            inforHolder.titleInforAdapterTv.setText(list.get(position).getTitle());
            inforHolder.descripInforAdapterTv.setText(list.get(position).getIntro());
            inforHolder.playCountsInforAdapterTv.setText(
                    CountToOthers.getCountToWan(list.get(position).getPlaysCounts()));
            inforHolder.tracksInforAdapterTv.setText(list.get(position).getTracksCounts() + "集");

            inforHolder.inforAdapterIv.setImageUrl(
                    list.get(position).getAlbumCoverUrl290(), BaseFragment.getImageLoader());
        }
        return convertView;
    }

    class InforTwoViewHolder {
        TextView titleInforAdapterTv, descripInforAdapterTv, playCountsInforAdapterTv, tracksInforAdapterTv;
        NetworkImageView inforAdapterIv;
        RelativeLayout relativeInforAdapter;

        public InforTwoViewHolder(View view) {
            titleInforAdapterTv = (TextView) view.findViewById(R.id.tvSubTitle_inforTwoAdapter);
            descripInforAdapterTv = (TextView) view.findViewById(R.id.tvDescrip_inforOneAdapter);
            playCountsInforAdapterTv = (TextView) view.findViewById(R.id.tvPlayCounts_inforOneAdapter);
            tracksInforAdapterTv = (TextView) view.findViewById(R.id.tvTracks_inforOneAdapter);
            inforAdapterIv = (NetworkImageView) view.findViewById(R.id.iv_inforOneAdapter);
        }
    }
}
